package com.hj.controller;

import com.hj.domain.User;
import com.hj.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/user")
@RefreshScope
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @Value("${server.port}")
    private int port;

    @Value("${test.name}")
    private String name;

    @RequestMapping("/findAll")
    @ResponseBody
    public List<User> findAll(){
        List<User> userList = userMapper.findAll();
        System.out.println("服务端口"+port+"被调用");
        return userList;
    }

    @RequestMapping("/findUserById")
    @ResponseBody
    public User findByUserId(@RequestParam("id") Integer id){
        User User = userMapper.findUserById(id);
        User.setEmail("服务端口"+port+"被调用,名字是："+name);
        return User;
    }

    @RequestMapping("/testMethod")
    @ResponseBody
    public String testMethod(){
        return "hujian";
    }
}
